package com.delay.queue.delayedqueue.jdkScheduledExecutorService;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @author gxing
 * @desc
 * @date 2021/3/16
 */
@Component
public class ScheduledTaskExecutor implements CommandLineRunner {
    private static final Logger logger = LogManager.getLogger(ScheduledTaskExecutor.class);

    private static final ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);

    @Override
    public void run(String... args) throws Exception {
        this.taskProcess();
    }

    private void taskProcess() {
        logger.info("任务处理启动:{}", System.currentTimeMillis() / 1000);

/*        executor.scheduleWithFixedDelay(new Runnable() {
            @Override
            public void run() {
                logger.info("处理业务:{}", System.currentTimeMillis() / 1000);
            }
        }, 3, 5, TimeUnit.SECONDS);*/
    }
}
